package com.cbtx.module.base.ui;

import android.annotation.SuppressLint;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

/**
 * author Lambert on 2019-11-09
 */
public class BaseFragmentPagerAdapter extends FragmentPagerAdapter {

    public static final int BEHAVIOR_SET_USER_VISIBLE_HINT = 0;
    public static final int BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT = 1;

    private List<Fragment> mFragmentList;
    private List<String> titles;


    @SuppressLint("WrongConstant")
    public BaseFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm); //Androidx 适应懒加载的做法
        mFragmentList = fragments;
    }

    @SuppressLint("WrongConstant")
    public BaseFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragments, List<String> titles) {
        super(fm); //Androidx 适应懒加载的做法
        mFragmentList = fragments;
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        if (mFragmentList != null) {
            return mFragmentList.size();
        }
        return 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (titles == null || titles.size() < position) {
            return null;
        }
        return titles.get(position);
    }

}
